<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="org.jbpm.graph.def.*" %>
<%@ page import="org.jbpm.graph.exe.*" %>
<%@ page import="org.jbpm.taskmgmt.exe.*" %>
<%@ page import="org.jbpm.*" %>
<%@ page import="com.gzgi.workflow.jbpm.context.*" %>
<%@ page import="com.gzgi.workflow.jbpm.service.*" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ include file="/pages/system/checkAdmin.jsp"%>
<%
      
	   String processInstanceId = request.getParameter("processInstanceId");
	   if(StringUtils.isNumeric(processInstanceId)){
		    JbpmContext jbpmContext = null;
			try {
				JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
			    jbpmContext = jbpmConfiguration.createJbpmContext();
				if (jbpmContext.getSession() != null) {
					    ProcessInstance processInstance = jbpmContext.loadProcessInstanceForUpdate(new Long(processInstanceId).longValue());
						if (processInstance.hasEnded()) {
								out.println("==================流程已经完成，无须挂起================");
								return;
						}

						/**
						 * 只把任务挂起
						*/
						 TaskMgmtInstance tmi = processInstance.getTaskMgmtInstance();
						 Collection taskInstances = tmi.getTaskInstances();
						 if (taskInstances != null) {
							Iterator iter = taskInstances.iterator();
							while (iter.hasNext()) {
								TaskInstance taskInstance = (TaskInstance) iter.next();
								if (taskInstance.isOpen()) {
									taskInstance.suspend();
								}
							}
						 }				
				}
			} catch (Exception ex) {
				jbpmContext.setRollbackOnly();
				throw new org.jbpm.JbpmException(ex);
			} finally {
				Context.close(jbpmContext);
			}
	   }
%>
<%@ include file="/pages/tm/header.jsp"%>
<script language="JavaScript">
    function submitForm(){
		document.iForm.bt01.disabled=true;
        document.iForm.submit();
     }
</script>
<center>
<br><br>
<form name="iForm" method="post" action="" class="x-form">
<div style="width:60%;" align="center">
        <div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>
        <div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc">
            <h3 style="margin-bottom:5px;">
			<img src="<%=request.getContextPath()%>/pages/images/window.png" alt="挂起任务">&nbsp;挂起任务</h3>
            
            <div class="x-form-bd" id="container">

                <fieldset>
                    <legend>挂起任务</legend>
					<table align="center" width="90%" border="0" cellspacing="1" cellpadding="0" class="list-box">
					  <tr class="list-title">
					    <td align="left" width="150">流程实例编号</td>
					    <td align="left">
					      <input type="text" id="processInstanceId" name="processInstanceId" size="50"  value="" class="x-form-text">
					    </td>
				     </tr>				
				   </table>
				</fieldset>

            </div>

			 <div align="center">
				     <br/>
					     <input type="button" name="bt01" value=" 确 定 " onclick="submitForm();" class="button">
					 <br/><br/>
		   </div>

        </div></div></div>
        <div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>
    </div>
</form>
</center>
